<template>
	<div class="app-container">
		<list-frames :loading="loading">
			<el-form slot="form" :model="queryData" ref="queryForm" size="small" :inline="true" v-if="showSearch">
				<el-form-item prop="postName">
					<el-input v-model="queryData.postName" placeholder="请输入岗位名称" clearable style="width: 150px" />
				</el-form-item>
				<el-form-item prop="spPostLevel">
					<el-select v-model="queryData.spPostLevel" placeholder="选择涉密等级" clearable style="width: 128px">
						<el-option v-for="(item, index) in dictData.sp_level" :key="index" :label="item.label" :value="item.value"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item prop="postBasis">
					<el-select v-model="queryData.postBasis" placeholder="选择岗位确定依据" clearable style="width: 154px">
						<el-option v-for="(item, index) in dictData.sp_post_basis" :key="index" :label="item.label" :value="item.value"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item prop="highestDegree">
					<el-select v-model="queryData.highestDegree" placeholder="选择最高学历" clearable style="width: 128px">
						<el-option v-for="(item, index) in dictData.sp_highest_degree" :key="index" :label="item.label" :value="item.value"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="el-icon-search" @click="queryTableData()">搜索</el-button>
				</el-form-item>
				<el-form-item>
					<el-button icon="el-icon-refresh" @click="handleResetQuery()">重置</el-button>
				</el-form-item>
			</el-form>
			<template slot="button">
				<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleOpenDialog()" v-hasPermi="['spm:spPost:add']">新增</el-button>
				<template v-if="checkedIds.length > 0">
					<el-button type="danger" plain icon="el-icon-delete" size="mini" @click="handleDeleteData()" v-hasPermi="['spm:spPost:remove']">
						删除
					</el-button>
				</template>
				<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExportData()" v-hasPermi="['spm:spPost:export']">
					导出
				</el-button>
			</template>
			<right-toolbar slot="handle" :showSearch.sync="showSearch" @queryTable="queryTableData()"></right-toolbar>
			<el-table slot="table" height="100%" :data="tableData" @selection-change="handleSelectionChange($event, 'postId')">
				<el-table-column type="selection" width="42" align="center" />
				<el-table-column label="岗位名称" prop="postName" min-width="150" />
				<el-table-column label="涉密等级" align="center" prop="spPostLevel" min-width="80">
					<template slot-scope="{ row }">
						<dict-tag :options="dictData.sp_level" :value="row.spPostLevel" />
					</template>
				</el-table-column>
				<el-table-column label="岗位确定依据" align="center" prop="postBasis" min-width="100">
					<template slot-scope="{ row }">
						<dict-tag :options="dictData.sp_post_basis" :value="row.postBasis" />
					</template>
				</el-table-column>
				<el-table-column label="岗位类型" align="center" prop="postType" min-width="80">
					<template slot-scope="{ row }">
						<dict-tag :options="dictData.sp_project_type" :value="row.postType" />
					</template>
				</el-table-column>
				<el-table-column label="管理干部类型" align="center" prop="managementType" min-width="100">
					<template slot-scope="{ row }">
						<dict-tag :options="dictData.sp_leader_type" :value="row.managementType" />
					</template>
				</el-table-column>
				<el-table-column label="最高学历" align="center" prop="highestDegree" min-width="80">
					<template slot-scope="{ row }">
						<dict-tag :options="dictData.sp_highest_degree" :value="row.highestDegree" />
					</template>
				</el-table-column>
				<el-table-column label="岗位人员" align="center" prop="spUserName" min-width="80" />
				<el-table-column label="岗位职能" prop="postFunction" min-width="240" show-overflow-tooltip />
				<el-table-column label="操作" width="116" class-name="small-padding fixed-width">
					<template slot-scope="{ row }">
						<el-button type="text" icon="el-icon-edit" @click="handleOpenDialog(row.postId)" v-hasPermi="['spm:spPost:edit']">修改</el-button>
						<el-button type="text" icon="el-icon-delete" @click="handleDeleteData(row.postId)" v-hasPermi="['spm:spPost:remove']">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
			<template slot="page" v-if="dataCount > 0">
				<pagination :total="dataCount" :page.sync="queryData.pageNum" :limit.sync="queryData.pageSize" @pagination="queryTableData()" />
			</template>
		</list-frames>
		<form-dialog v-model="formDialog" :data-id="dataId" :dict-data="dictData" @finish="queryTableData()"></form-dialog>
	</div>
</template>

<script>
import formDialog from './form';
import listMixins from '../common/listMixins';
import { listSpPost, delSpPost } from '@/api/personnal/spPost';
export default {
	name: 'SpPost',
	mixins: [listMixins],
	components: { formDialog },
	dicts: ['sp_level', 'sp_post_basis', 'sp_highest_degree', 'sp_project_type', 'sp_leader_type'],
	data() {
		return {
			pageName: '岗位'
		};
	},
	computed: {
		userId() {
			return this.$route.query.id;
		},
		delFunction() {
			return eval(delSpPost);
		},
		exportUrl() {
			return 'spm/level/export';
		}
	},
	methods: {
		//获取列表数据
		async getTableData() {
			let params = { ...this.queryData };
			console.log(params);
			let result = await listSpPost(params);
			console.log(result);
			this.loading = false;
			if (result.code === 200) {
				this.dataCount = result.total;
				this.tableData = result.rows || [];
			}
		}
	}
};
</script>
